package com.example.haoqisystem.controller;

import com.example.haoqisystem.entity.QuestionNaire;
import com.example.haoqisystem.entity.TrainningPlan;
import com.example.haoqisystem.request.*;
import com.example.haoqisystem.response.BaseResponse;
import com.example.haoqisystem.response.PageResult;
import com.example.haoqisystem.response.QuestionnaireResultResponse;
import com.example.haoqisystem.service.QuestionNaireService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "调查问卷api")
@RestController
@RequiredArgsConstructor(onConstructor_ ={@Autowired} )
@RequestMapping("/questionnaire")
public class QuestionnaireController {
    private final QuestionNaireService questionNaireService;
    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public BaseResponse<QuestionNaire> add(@RequestBody CreateQuestionNaireRequest request){
        return questionNaireService.add(request);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/detail")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "调查问卷id",required = true)
    })
    public BaseResponse<QuestionNaire> detail(Long id){
        return questionNaireService.detail(id);
    }

    @ApiOperation(value = "更新")
    @PutMapping("/update")
    public BaseResponse<QuestionNaire> update(@RequestBody UpdateQuestionNaireRequest request){
        return questionNaireService.update(request);
    }

    @ApiOperation(value = "删除")
    @DeleteMapping("/delete")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ids",value = "调查问卷id",required = true)
    })
    public BaseResponse<String> delete(List<Long> ids){
        return questionNaireService.delete(ids);
    }

    @ApiOperation(value = "分页列表查询")
    @PostMapping("/queryListPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "deleted",value = "逻辑删除（0，1）",required = true),
            @ApiImplicitParam(name = "pageNum",value = "页数",required = true),
            @ApiImplicitParam(name = "pageSize",value = "每页大小",required = true)
    })
    public BaseResponse<PageResult<QuestionNaire>>queryList(QueryQuestionNaireRequest request){
        return questionNaireService.queryList(request);
    }

    @ApiOperation(value = "列表查询")
    @GetMapping("/queryList")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "课程id")
    })
    public BaseResponse<List<QuestionNaire>> querylist(Long id){
        return questionNaireService.queryList1(id);
    }

    @ApiOperation(value = "查询调查问卷的结果（返回评价均值，各分段比例)")
    @GetMapping("/result")
    public BaseResponse<QuestionnaireResultResponse> findResult(@RequestParam("lectureId") Long lectureId){
        return questionNaireService.findResult(lectureId);
    }

}
